<?php
/**
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
* @property CI_DB_active_record $db
*
*/
class Register extends CI_Controller
{
    function  __construct()
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->model('Newconnection');

    }
    function index()
    {
         $data["title"]="New Connection";
         $data["content"]="register/new_content";
         $data["sidebar"]="register/new_sidebar";
         $js[]="new_connection.js";
         $js[]="jquery.validate.js";
         $data["js"]=$js;
         $this->load->model('Exchange');
         $data["exchange"]=  $this->Exchange->exchange_list();
         $this->load->view("template",$data);

    }
    function submit()
    {
        $code=$_POST["exchange"];
        $_POST["birthday"] = date("Y-m-d",strtotime($_POST["birthday"]) );
       // echo $_POST["birthday"] ;
        unset($_POST["exchange"]);
//        foreach ($_POST as $i)
//                echo $i."<br/>";
       // print_r($_POST);
        $this->db->where($_POST);
        $query=$this->db->get('applicant');
        if($query->num_rows()==0)
        {
            $this->db->trans_start();

            $this->db->insert('applicant',$_POST);
            $id=$this->db->insert_id();

            $this->db->query("insert into newconnection (appid,status,message,updatedate) values($id,'Recent','Your application is sent to Divisional Engineer',NOW())");

            $this->load->model("Employee");
            $de=$this->Employee->get_DE($code);
            $this->load->model("Newhandle");
            $this->Newhandle->insert($id,$de,$code);

            $this->db->trans_complete();
            $this->confirm("Your Application number is ".$id.". Remember this and use for checking status of your Application.");
        }
        else
        {
            $this->confirm("You have already applied for New Connection");
        }
    }
    function confirm($msg="Your Application no is 420")
    {
         $data["title"]="Confirmation";
         $data["content"]="register/confirm";
         $data["sidebar"]="admin/sidebar";
         $js[]="admin.js";
         $data["js"]=$js;
         $data["msg"]=$msg;
         $this->load->view("template",$data);
    }
 
    
    function image()
    {
        $data["title"]="Image uploader";
        $data["content"]="register/img_view";
        $data["sidebar"]="register/shift_sidebar";
        $data["js"]="shift_connection.js";
        $this->load->view("template",$data);
    }
    function new_check_status()
    {
        $data["title"]="Check Status";
        $data["content"]="register/new_check_status";
        $data["sidebar"]="admin/sidebar";
         $js[]="new_check_status.js";
         $data["js"]=$js;
         $this->load->view("template",$data);
    }
    function new_fetch_ajax()
    {
        
      //  $data["appid"]="sds";
        echo json_encode($this->Newconnection->get_status($_POST));
    }
}
?>
